<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

class selectItems extends CWidget {

	public $type;
	public $value;

	public function run() {
		if (empty($this->type)) {
			Yii::log("Вы не указали тип данных", 'error');
		}
		$models = Yii::app()->db->createCommand("SELECT \"pageId\", \"pageTitle\" FROM {{pages}} WHERE \"pageType\"='{$this->type}';")->queryAll(TRUE);
		foreach ($models as $model) {
			$array['id'] = CHtml::encode($model['pageId']);
			$array['title'] = CHtml::encode($model['pageTitle']);
			$return[] = $array;
		}
		$items = json_encode($return, 1);
		$this->render('selectItems', array('items' => $items, 'value' => $this->value));
	}

}
